import type {IColumnsOption} from 'vc';
import {
  INDEX,
} from '@/utils/tableColumn';
import {toF9, setHrefUrlTool, toBondDetail} from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    {...INDEX},
    {
      field: 'bondShortName',
      title: '债券简称',
      width: 260,
      fixed: 'left',
      headerAlign: 'center',
      sortBy: 'bondShortName',
      slots: {
        default: ({row}) => {
          const content = row.highlight?.bondShortName ? row.highlight?.bondShortName : row.bondShortName;
          return <div>
            <a title={row.bondShortName} class="companyName"
               onClick={() => toBondDetail(row.id)}
               v-html={content}>

            </a>
            {row.expired ? <span class="bondTypeLabel"
                                 style={'color:#fff;background:#fb9196'}>已过期 </span> : ''}
          </div>;
        }
      }

    },
    {
      field: 'securitiesCode',
      title: '债券代码',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'securitiesCode'
    },
    {
      width: 200,
      field: 'attachments',
      title: '绿债口径/品种',
      slots: {
        default: ({row}) => {
          if (row.labels?.length === 0) {
            return '-';
          }
          return row?.labels?.map((item) => {
            return (
              <span class="bondTypeLabel"
                    style={'color:' + item.color + ';background:' + item.bgColor}>
                {item.name}
              </span>
            );
          });
        }
      }
    },
    {
      field: 'greenProjectClassifications',
      title: '绿债分类',
      align: 'center',
      width: 200,
      showOverflow: 'title',
      slots: {
        default: ({row}) => {
          if (row.greenProjectClassifications && row.greenProjectClassifications.length > 0) {
            return <span class="line-clamp">{row.greenProjectClassifications.join('、')}</span>
          } else {
            return <span class="line-clamp">-</span>
          }
        }
      }
    },
    {
      field: 'bondTypeName',
      title: '债券类型',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'bondTypeName'
    },
    {
      field: 'bondPeriod',
      title: '债券期限',
      align: 'center',
      width: 110,
      sortBy: 'bondPeriod'
    },
    {
      field: 'issuingScale',
      title: '发行规模',
      align: 'center',
      // sortable: true,
      sortBy: 'issuingScale',
      width: 110,
      formatter: ({row}) => {
        return row.issuingScale ? row.issuingScale + '亿' : '-';
      }
    },
    {
      field: 'issuingDate',
      title: '发行起始日',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'issuingDate'
    },
    {
      field: 'couponRateDisplay',
      title: '票面利率',
      align: 'center',
      // sortable: true,
      sortBy: 'couponRate',
      width: 110,
      formatter: ({row}) => {
        return row.couponRateDisplay ? row.couponRateDisplay + '%' : '-';
      }
    },
    {
      field: 'calculateInterestMethod',
      title: '计息方式',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'calculateInterestMethod'
    },
    {
      field: 'valueDate',
      title: '起息日',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'valueDate'
    },
    {
      field: 'maturityDate',
      title: '到期日',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'maturityDate'
    },
    {
      field: 'facilityRating',
      title: '债券评级',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'facilityRating'
    },
  ]);

  return {
    columns,
  };
}
